package com.example.qggoodsprovider.controller;

import com.example.qggoodsprovider.service.GoodsService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;

@RestController
public class GoodsController {

    @Resource
    private GoodsService service;

    @RequestMapping("/getAllGoods")
    public List<Map> getAllGoods(){
        return service.getAllGoods();
    }

    //查询所有商品以及每一个商品的被抢购数
    @RequestMapping("/getAllGoodsByQgTotal")
    public List<Map> getAllGoodsByQgTotal(){
      return service.getAllGoodsByQgTotal();
    }

    @RequestMapping("/addTempSotck")
    public int  addTempSotck(@RequestParam Map map){
        service.addTempSotck( map );
        return ((BigInteger)map.get("id")).intValue();
    }
    @RequestMapping("/getStock")
    public int getStock(@RequestParam("goodsId") int goodsId){
        return service.getStock( goodsId );
    }

    @RequestMapping("/getQgTotalByGoodsId")
    public int getQgTotalByGoodsId(@RequestParam("goodsId") int goodsId){
        return service.getQgTotalByGoodsId( goodsId );
    }

    @RequestMapping("/getCountByGoodsIdUid")
    public int getCountByGoodsIdUid(@RequestParam Map map) {
        return service.getCountByGoodsIdUid(map);
    }
    @RequestMapping("/getById")
    public Map getById(@RequestParam("goodsId") int goodsId){
        return service.getById(goodsId);
    }
//
//    @RequestMapping("/addTempSotck")
//    public int addTempSotck(@RequestParam Map map){
//        return service.addTempSotck(map);
//    }

}
